package com.ssy.wireless.util;

import java.io.Serializable;

/**
 * Created by cofey on 16/11/24.
 */
public class RespVo<T extends Serializable> implements Serializable {
    private int errorCode;
    private String errorMessage;
    private T result;

    private RespVo() {
    }

    public RespVo(int errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public T getResult() {
        return result;
    }

    public RespVo<T> setResult(T result) {
        this.result = result;
        return this;
    }

    public static <T extends Serializable> RespVo<T> success() {
        return new RespVo(0, "ok");
    }

    public static <T extends Serializable> RespVo<T> success(T resBody) {
        return (new RespVo(0, "ok")).setResult(resBody);
    }

    public static <T extends Serializable> RespVo<T> error(String errorMessage) {
        return new RespVo(500, errorMessage);
    }

    public static <T extends Serializable> RespVo<T> error(int errorCode, String errorMessage) {
        return new RespVo(errorCode, errorMessage);
    }
}
